Mortgage Demo Example

[1]:
from cuXfilter import charts
import cuXfilter
from bokeh import palettes
from cuXfilter.layouts import layout_1, layout_2
import warnings
warnings.filterwarnings('ignore')

Load cuXfilter dataframe

[2]:
cux_df = cuXfilter.DataFrame.from_arrow('/home/ajay/data/146M_predictions_v2.arrow')

Define Charts

[3]:
chart0 = charts.bokeh.choropleth(x='zip', y='delinquency_12_prediction', aggregate_fn='mean',
                                  geo_color_palette=palettes.Inferno256,
                                  geoJSONSource = 'https://raw.githubusercontent.com/rapidsai/cuxfilter/master/demos/GTC%20demo/src/data/zip3-ms-rhs-lessprops.json',
                                  data_points=1000, width=1100, x_range=(-126, -66), y_range=(23, 50))
chart2 = charts.bokeh.bar('delinquency_12_prediction',data_points=50, width=400, height=400)
chart3 = charts.panel_widgets.range_slider('borrower_credit_score',data_points=50,width=400, height=400)

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-3-4abbb8b2ebd2> in <module>
      2                                   geo_color_palette=palettes.Inferno256,
      3                                   geoJSONSource = 'https://raw.githubusercontent.com/rapidsai/cuxfilter/master/demos/GTC%20demo/src/data/zip3-ms-rhs-lessprops.json',
----> 4                                   data_points=1000, width=1100, x_range=(-126, -66), y_range=(23, 50))
      5 chart2 = charts.bokeh.bar('delinquency_12_prediction',data_points=50, width=400, height=400)
      6 chart3 = charts.panel_widgets.range_slider('borrower_credit_score',data_points=50,width=400, height=400)

~/cuxfilter-design/cuXfilter/charts/bokeh/bokeh.py in choropleth(x, y, data_points, add_interaction, aggregate_fn, width, height, step_size, step_size_type, geoJSONSource, geoJSONProperty, geo_color_palette, **library_specific_params)
    126     A bokeh chart object of type choropleth
    127     """
--> 128     return plots.Choropleth(x, y, data_points, add_interaction, aggregate_fn, width, height, step_size, step_size_type, geoJSONSource, geoJSONProperty, geo_color_palette, **library_specific_params)
    129
    130 def data_size_indicator(width=400, height=50, **library_specific_params):

~/cuxfilter-design/cuXfilter/charts/core/aggregate/core_aggregate_choropleth.py in __init__(self, x, y, data_points, add_interaction, aggregate_fn, width, height, step_size, step_size_type, geoJSONSource, geoJSONProperty, geo_color_palette, **library_specific_params)
     70         self.geo_color_palette = geo_color_palette
     71         self.geoJSONProperty = geoJSONProperty
---> 72         self.geo_mapper = geo_json_mapper(self.geoJSONSource, self.geoJSONProperty)
     73         self.height = height
     74         self.width = width

~/cuxfilter-design/cuXfilter/assets/geojson_mapper.py in geo_json_mapper(url, prop)
      3
      4 def geo_json_mapper(url, prop=None):
----> 5     data = urlopen(url).read().decode()
      6     data_json = json.loads(data)
      7     if prop == '' or prop is None:

~/anaconda3/envs/cudf_0.8/lib/python3.7/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    220     else:
    221         opener = _opener
--> 222     return opener.open(url, data, timeout)
    223
    224 def install_opener(opener):

~/anaconda3/envs/cudf_0.8/lib/python3.7/urllib/request.py in open(self, fullurl, data, timeout)
    529         for processor in self.process_response.get(protocol, []):
    530             meth = getattr(processor, meth_name)
--> 531             response = meth(req, response)
    532
    533         return response

~/anaconda3/envs/cudf_0.8/lib/python3.7/urllib/request.py in http_response(self, request, response)
    639         if not (200 <= code < 300):
    640             response = self.parent.error(
--> 641                 'http', request, response, code, msg, hdrs)
    642
    643         return response

~/anaconda3/envs/cudf_0.8/lib/python3.7/urllib/request.py in error(self, proto, *args)
    567         if http_err:
    568             args = (dict, 'default', 'http_error_default') + orig_args
--> 569             return self._call_chain(*args)
    570
    571 # XXX probably also want an abstract factory that knows when it makes

~/anaconda3/envs/cudf_0.8/lib/python3.7/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    501         for handler in handlers:
    502             func = getattr(handler, meth_name)
--> 503             result = func(*args)
    504             if result is not None:
    505                 return result

~/anaconda3/envs/cudf_0.8/lib/python3.7/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    647 class HTTPDefaultErrorHandler(BaseHandler):
    648     def http_error_default(self, req, fp, code, msg, hdrs):
--> 649         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    650
    651 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 404: Not Found

Add mappings for chart1

[4]:
mapper1 = {}

for val in cux_df.data.dti.unique().to_pandas().tolist():
    mapper1[int(val)] = 'l_'+str(val)

chart1 = charts.panel_widgets.multi_select('dti', width=400, height=400, label_map=mapper1)
#also available: panel_widgets.dropdown

Create dashboard

[5]:
d = cux_df.dashboard([chart0, chart1], layout=layout_2, title="Ajay's Dashboard")
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-681296ffd3a7> in <module>
----> 1 d = cux_df.dashboard([chart0, chart1], layout=layout_2, title="Ajay's Dashboard")

NameError: name 'chart0' is not defined
[6]:
#add more charts
d.add_charts([chart2, chart3])
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-6-676510c54145> in <module>
      1 #add more charts
----> 2 d.add_charts([chart2, chart3])

NameError: name 'd' is not defined
[7]:
# d.show('url you want the dashboard to run') remote dashboard:
# d.app('10.110.47.43:8888') within the notebook: If you are using jupyter remotely, use this line instead of second, and replace url with current notebook url
#d.app() for local interactive behavior

#d.view() for just a view of the dashboard, interaciton not available. Recommended way to generate when uploading to git remote site
d.view()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-7-580038cfbd3d> in <module>
      4
      5 #d.view() for just a view of the dashboard, interaciton not available. Recommended way to generate when uploading to git remote site
----> 6 d.view()

NameError: name 'd' is not defined

Export the queried data into a dataframe

[8]:
queried_df = d.export()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-8-5f1dbc176995> in <module>
----> 1 queried_df = d.export()

NameError: name 'd' is not defined